//
//  HJAlertOneClickeView.m
//  project
//
//  Created by yefei on 2019/6/6.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJAlertOneClickeView.h"
@interface HJAlertOneClickeView ()
@property (weak, nonatomic) IBOutlet UIImageView *MainImage;
@property (weak, nonatomic) IBOutlet UILabel *content;
@property (weak, nonatomic) IBOutlet UIButton *publicBtn;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@end


@implementation HJAlertOneClickeView

+(instancetype)alertOneView {
    HJAlertOneClickeView * alertView = [[NSBundle mainBundle] loadNibNamed:@"HJAlertOneClickeView" owner:nil options:nil].firstObject;
    alertView.frame = [UIScreen mainScreen].bounds;
    return alertView;
}

-(void)show {
    self.alpha = 0;
    self.bgView.transform = CGAffineTransformMakeScale(0, 0);
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.alpha = 1;
        self.bgView.transform = CGAffineTransformMakeScale(1.7, 1.7);
        self.bgView.transform = CGAffineTransformMakeScale(1, 1);
    } completion:^(BOOL finished) {
        self.bgView.transform = CGAffineTransformIdentity;
    }];
}

-(void)dismiss {
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:1 options:(UIViewAnimationOptionCurveEaseOut) animations:^{
        self.alpha = 0;
        self.bgView.transform = CGAffineTransformMakeScale(0, 0);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
        self.bgView.alpha = 1;
        self.bgView.transform = CGAffineTransformIdentity;
    }];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setupViews];
    }
    return  self;
}
-(void)awakeFromNib {
    [super awakeFromNib];
    [self setupViews];
}

-(void)setupViews {
    [self.bgView rounded:UIRectCornerAllCorners radius:12 borderColor:[UIColor colorWithHex:0xDCDCDC] borderWidth:1];
    [self.publicBtn rounded:UIRectCornerAllCorners radius:0 borderColor:[UIColor colorWithHex:0xDCDCDC] borderWidth:1];
    
    @weakify(self)
    [[self.publicBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        self.actionBlock();
        [self dismiss];
    }];
}

-(void)setTitle:(NSString *)title {
    self.content.text = title;
}

-(void)setOkTitle:(NSString *)okTitle {
    [self.publicBtn setTitle:okTitle forState:0];
}



@end
